#include "stackwidget.h"
#include "ui_stackwidget.h"
#include<QDebug>

StackWidget::StackWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::StackWidget)
{
//    this->setAttribute(Qt::WA_DeleteOnClose, true);
    //设置无边框
    this->setWindowFlags(Qt::FramelessWindowHint);

    ui->setupUi(this);
//    //关闭窗口，即销毁窗体
//    this->setAttribute(Qt::WA_DeleteOnClose, true);

    //设置窗口图标
    this->setWindowIcon(QIcon(":/images/软件图标.png"));
    det=new detection;
    his=new history;
    sett=new setting;



    ui->stackedWidget->addWidget(det);
    ui->stackedWidget->addWidget(his);
    ui->stackedWidget->addWidget(sett);

    //首页
    ui->stackedWidget->setCurrentWidget(det);

    ui->label_username->setText(login::Qname);
    
}

StackWidget::~StackWidget()
{
    delete ui;
    delete det;
    delete his;
    delete sett;
    qDebug()<<"delete stackwidget";
}

//检测界面
void StackWidget::on_pushButton_detecting_clicked()
{

    ui->stackedWidget->setCurrentWidget(det);
}

//历史记录界面（每点一次，刷新一次）
void StackWidget::on_pushButton_history_clicked()
{

    his->flash();//刷新一下表格
    ui->stackedWidget->setCurrentWidget(his);

}

//设置界面
void StackWidget::on_pushButton_setting_clicked()
{
    ui->stackedWidget->setCurrentWidget(sett);
}
//退出
void StackWidget::on_pushButton_clicked()
{
    //发送关闭标题栏的信号
    emit sendsignal();

//    delete det;
//   delete  his;
//    delete sett;
//    his->close();
    this->close();
//    this->deleteLater();
    //自定义标题栏
    titlebarFix *tBar=new titlebarFix;
    login*lo=new login;
    connect(lo,SIGNAL(sendsignal()),tBar,SLOT(close()));
    tBar->setAttribute(Qt::WA_DeleteOnClose, true);
    tBar->setMainWidget(lo);
    tBar->setTitleBarText(QStringLiteral("登陆界面"));
    tBar->show();

//    lo->show();

}


//判断数据库是否连接
void StackWidget::testDatabaseConnection()
{

}
